using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using OF.Utility;
using OF.Component.Model;
using OF.Component.BLL;

namespace OF.Component.Base
{
    /// <summary>
    /// 后台管理页面基类
    /// </summary>
    public abstract class CommonPage : PersistencePage
    {
        /// <summary>
        /// 图片引用路径前缀
        /// </summary>
        public static string ImgPrefixPlaceHolder = "$Root$";
        public static string UpLoadImage
        {
            get
            {
                string strpath = RequestUtility.GetMapPathString() + SiteUtility.GetAppSettings("UpLoadImage");
                if (SiteUtility.GetAppSettings("UpLoadImage").IndexOf(":") > -1)
                {
                    strpath = SiteUtility.GetAppSettings("UpLoadImage");
                }

                return strpath;
            }
        }
        public static string ImagesUrl
        {
            get
            {
                return SiteUtility.GetAppSettings("ImagesUrl");
            }
        }
        /// <summary>
        /// 获取车务知识标题图的http图片路径地址
        /// </summary>
        /// <returns></returns>
        public string GetTitleImgUrl(string imgUrl)
        {
            string szReturn = String.Empty;
            if (!string.IsNullOrEmpty(imgUrl))
            {
                szReturn = ImagesUrl + "/" + imgUrl;
            }
            return szReturn;
        }
        /// <summary>
        /// 获取车务知识文章内容，并替换内容中的图片点位符
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public string GetArticleContent(string content)
        {
            string szReturn = String.Empty;
            if (!string.IsNullOrEmpty(content))
            {
                szReturn = content.Replace(ImgPrefixPlaceHolder,ImagesUrl);
            }
            return szReturn;
        }

        public static int SystemID
        {
            get
            {
                return  EConvert.ToInt(SiteUtility.GetAppSettings("systemid"));
            }
        }
        #region"后台调用JS"
        /// <summary>
        /// 输出提示信息1000毫秒后跳转父页面
        /// </summary>
        /// <param name="strMsg">提示信息</param>
        /// <param name="strUrl">跳转的URL</param>
        /// <returns>JS</returns>
        protected static string MessageInfoTop(string strMsg, string strUrl)
        {
            return " $().AjaxManage.MessageOpen(\"" + strMsg + "\");;setTimeout(\"top.window.location.href='" + strUrl + "'\", 1000);";
        }
        /// <summary>
        /// 输出提示信息1000毫秒后跳转当前页面
        /// </summary>
        /// <param name="strMsg">提示信息</param>
        /// <param name="strUrl">跳转的</param>
        /// <returns>JS</returns>
        protected static string MessageInfo(string strMsg, string strUrl)
        {
            return " $().AjaxManage.MessageOpen(\"" + strMsg + "\");;setTimeout(\"window.location.href='" + strUrl + "'\", 1000);";
        }
       
        /// <summary>
        /// 输出提示信息1000毫秒后跳转父页面如果strUrl为空则刷新父页面
        /// </summary>
        /// <param name="strMsg">提示信息</param>
        /// <param name="strUrl">跳转的</param>
        /// <returns></returns>
        protected static string MessageDivInfo(string strMsg, string strUrl)
        {
           
            string strMessage = " top.$().AjaxManage.MessageOpen(\"" + strMsg + "\");setTimeout(\"top.window.location.href=top.window.location.href\", 1000);";
            //string strMessage = " top.$().AjaxManage.MessageOpen(\"" + strMsg + "\");setTimeout(\"top.$().AjaxManage.MessageClose();top._M.CloseIframe();\", 1000);";
            if (!string.IsNullOrEmpty(strUrl))
                strMessage = " top.$().AjaxManage.MessageOpen(\"" + strMsg + "\"); setTimeout(\"top.window.location.href='" + strUrl + "'\", 1000);";

            return strMessage;
        }
        /// <summary>
        /// 输出提示信息1000毫秒后跳转父页面如果strUrl为空则刷新父页面
        /// </summary>
        /// <param name="strMsg">提示信息</param>
        /// <returns></returns>
        protected static string MessageDivInfoNoRedirect(string strMsg)
        {
            string strMessage = " top.$().AjaxManage.MessageOpen(\"" + strMsg + "\"); setTimeout(\"top.$().AjaxManage.MessageClose();\", 2000);";
            return strMessage;
            ////string strMessage = " top.$().AjaxManage.MessageOpen(\"" + strMsg + "\");";
            ////return strMessage;
        }

        /// <summary>
        /// 省份职级
        /// </summary>
        /// <param name="ddlLocation"></param>
        public static void BindLocation(ref System.Web.UI.WebControls.DropDownList ddlLocation, int Pid, int seltype)
        {
            DataTable list = BaseLocationOperate.GetLocation(Pid);
            ddlLocation.DataSource = list;
            ddlLocation.DataTextField = "LocationName";
            ddlLocation.DataValueField = "LocationID";
            ddlLocation.DataBind();
            switch (seltype)
            {
                case 0:
                    //ddlLocation.Items.Insert(0, new ListItem("省份", ""));
                    break;
                case 1:
                    ddlLocation.Items.Insert(0, new ListItem("城市", ""));
                    break;
                case 2:
                    ddlLocation.Items.Insert(0, new ListItem("区县", ""));
                    break;
            }
        }
       /// <summary>
       /// 绑定数据字典项
       /// </summary>
       /// <param name="ddlCommon">下拉框</param>
       /// <param name="ClassID">字典分类ID</param>
       /// <param name="strdescription">下拉框第一个选项描述</param>
        public static void BindBaseDictionary(ref System.Web.UI.WebControls.DropDownList ddlCommon, int ClassID, string strdescription)
        {
           
            DataTable list = BaseDictionaryInfoOperate.GetBaseDictionaryListByClassID(ClassID);
            ddlCommon.DataSource = list;
            ddlCommon.DataTextField = "DictionaryName";
            ddlCommon.DataValueField = "DictionaryValue";
            ddlCommon.DataBind();
            if (!string.IsNullOrEmpty(strdescription))
            {
                ddlCommon.Items.Insert(0, new ListItem(strdescription, ""));
            }
        }
        /// <summary>
        /// 绑定数据字典项
        /// </summary>
        /// <param name="ddlCommon">下拉框</param>
        /// <param name="ClassID">字典分类ID</param>
        /// <param name="strdescription">下拉框第一个选项描述</param>
        public static void BindBaseDictionaryClass(ref System.Web.UI.WebControls.DropDownList ddlCommon, int GroupID, string strdescription)
        {

            IList<BaseDictionaryClassInfo> list = BaseDictionaryClassOperate.GetBaseDictionaryClassByGroupID(GroupID);
            ddlCommon.DataSource = list;
            ddlCommon.DataTextField = "DictionaryClassName";
            ddlCommon.DataValueField = "DictionaryClassID";
            ddlCommon.DataBind();
            if (!string.IsNullOrEmpty(strdescription))
            {
                ddlCommon.Items.Insert(0, new ListItem(strdescription, ""));
            }
        }
        #endregion

    }


}
